<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <a-form @keyup.enter.native="searchQuery">
      <a-row :gutter="24">
        <a-col :md="6" :sm="12">
          <a-form-item label="模型编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input placeholder="请输入模型编码" v-model="queryParam.modelCode"></a-input>
          </a-form-item>
        </a-col>
        <a-col :md="6" :sm="12">
          <a-form-item label="模型名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input placeholder="请输入模型名称" v-model="queryParam.modelName"></a-input>
          </a-form-item>
        </a-col>
        <a-col :md="6" :sm="12">
          <a-form-item label="模型类型" :label-col="labelCol" :wrapper-col="wrapperCol">
            <z-dict-select-tag popupContainer="parent" dictCode="MB_GEN_MODEL_TYPE"  v-model="queryParam['modelType@EQ']"/>
          </a-form-item>
        </a-col>
        <a-col :md="6" :sm="8">
          <a-form-item>
            <a-button type="primary" @click="searchQuery()" icon="search">查询</a-button>
            <a-button type="primary" @click="searchReset()" icon="reload" style="margin-left: 8px">重置</a-button>
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
    <vxe-grid
      id="GenList"
      ref="vxeTable"
      v-bind="gridOptions"
      :row-config="{keyField:'modelCode'}"
    >
      <template #action="{ row }">
        <a @click="handleEdit(row)">编辑</a>
        <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down" />
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a href="javascript:;">预览</a>
              </a-menu-item>
              <a-menu-item >
                <a href="javascript:;">发布</a>
              </a-menu-item>
              <a-menu-item>
                <a href="javascript:;" @click="handleGenerate(row)">代码生成</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(row.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
      </template>
    </vxe-grid>
    <GenModal @ok="modalFormOk" ref="modalForm" />
  </a-card>
</template>

<script>
import VxeTableListMixin from '@/mixins/VxeTableListMixin'
import ZDictSelectTag from '@/components/dict/ZDictSelectTag'
import GenModal from './modules/GenModal'
import { getAction } from '@/services/manage'
export default {
  name: 'GenList',
  components: { ZDictSelectTag, GenModal },
  mixins: [VxeTableListMixin],
  data() {
    return {
      columns: [
        { type: 'seq', width: 40 },
        { title: '模型编码', field: 'modelCode' },
        { title: '模型名称', field: 'modelName' },
        { title: '模型类型', field: 'modelType', formatter: 'dictText' },
        { title: '描述', field: 'modelDesc' },
        { title: '创建人', field: 'createBy', formatter: 'dictText' },
        { title: '创建时间', field: 'createTime' },
        { title: '更新时间', field: 'updateTime' },
        { title: '操作', slots: { default: 'action' }, width: 170 }
      ],
      url: {
        list: '/sys/generator/model/page',
        generate: '/sys/generator/model/generate/',
        delete: '/sys/generator/model/remove/',
        deleteBatch: '/sys/generator/model/remove/'
      },
      toolbarConfig: {
        export: false,
        import: false
      }
    }
  },
  methods: {
    handleGenerate(row) {
      getAction(this.url.generate + row.modelCode).then(res => {
        console.log(res)
      })
    }
  }
}
</script>

